const fs = require("fs");
const ws = fs.createWriteStream("test.txt", {
  highWaterMark: 3,
});

const date = "拉钩教育";
let source = date.split("");
let num = 0;
let flag = true;
function executeWrite() {
  flag = true;
  while (num !== source.length && flag) {
    flag = ws.write(source[num++]);
  }
}
executeWrite();

ws.on("drain", () => {
  executeWrite();
});

// 一次性写入
// ws.write(date, () => {
//   console.log("一次性写入成功");
// });
